package cn.iocoder.yudao.module.ride.service.membergrowthrecord;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.ride.controller.admin.membergrowthrecord.vo.*;
import cn.iocoder.yudao.module.ride.dal.dataobject.membergrowthrecord.MemberGrowthRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ride.dal.mysql.membergrowthrecord.MemberGrowthRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.ride.enums.ErrorCodeConstants.*;

/**
 * 会员成长值变动记录 Service 实现类
 *
 * @author tong
 */
@Service
@Validated
public class MemberGrowthRecordServiceImpl implements MemberGrowthRecordService {

    @Resource
    private MemberGrowthRecordMapper memberGrowthRecordMapper;

    @Override
    public Long createMemberGrowthRecord(MemberGrowthRecordSaveReqVO createReqVO) {
        // 插入
        MemberGrowthRecordDO memberGrowthRecord = BeanUtils.toBean(createReqVO, MemberGrowthRecordDO.class);
        memberGrowthRecordMapper.insert(memberGrowthRecord);

        // 返回
        return memberGrowthRecord.getId();
    }

    @Override
    public void updateMemberGrowthRecord(MemberGrowthRecordSaveReqVO updateReqVO) {
        // 校验存在
        validateMemberGrowthRecordExists(Long.valueOf(updateReqVO.getId()));
        // 更新
        MemberGrowthRecordDO updateObj = BeanUtils.toBean(updateReqVO, MemberGrowthRecordDO.class);
        memberGrowthRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteMemberGrowthRecord(Long id) {
        // 校验存在
        validateMemberGrowthRecordExists(id);
        // 删除
        memberGrowthRecordMapper.deleteById(id);
    }

    @Override
        public void deleteMemberGrowthRecordListByIds(List<Long> ids) {
        // 删除
        memberGrowthRecordMapper.deleteByIds(ids);
        }


    private void validateMemberGrowthRecordExists(Long id) {
        if (memberGrowthRecordMapper.selectById(id) == null) {
            throw exception(MEMBER_GROWTH_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public MemberGrowthRecordDO getMemberGrowthRecord(Long id) {
        return memberGrowthRecordMapper.selectById(id);
    }

    @Override
    public PageResult<MemberGrowthRecordDO> getMemberGrowthRecordPage(MemberGrowthRecordPageReqVO pageReqVO) {
        return memberGrowthRecordMapper.selectPage(pageReqVO);
    }

}